<template>
  <div>
    <a-modal
      centered
      :title="title"
      :width="1000"
      :visible="visible"
      @ok="handleOk"
      :confirmLoading="confirmLoading"
      @cancel="handleCancel"
      cancelText="关闭">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="8" :sm="8">
                <a-form-item label="指标名称" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
                  <j-input placeholder="请输入指标名称" v-model="queryParam.name"></j-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchResetBefore" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
            <a style="margin-left: 24px" @click="onClearSelected">取消勾选</a>
          </div>
          <a-table
            ref="table"
            size="middle"
            :scroll="{x:true}"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            class="j-table-force-nowrap"
            @change="handleTableChange">

            <span slot="dimensionInfoVoList" slot-scope="dimensionInfoVoList">
              <a-tag
                style="font-size: 14px; margin-top: 5px"
                v-for="(topic, index) in dimensionInfoVoList"
                :key="index"
                color="blue"
              >{{ topic.name }}</a-tag
              >
            </span>
            <span slot="isPercent" slot-scope="isPercent">
              {{ isPercent == 1 ? '是' : '否' }}
            </span>
          </a-table>
        </div>
      </a-card>
    </a-modal>
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction } from '@/api/manage'
export default {
  name: 'SelectScSituationIndexInfoModal',
  components: {
    // DepartModal
  },
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      confirmLoading: false,
      visible: false,
      catalogId: null,
      title: '添加指标',
      description: '',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '指标名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '维度',
          align: 'center',
          dataIndex: 'dimensionInfoVoList',
          scopedSlots: { customRender: 'dimensionInfoVoList' }
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '数据类型',
          align: 'center',
          dataIndex: 'dataType_dictText'
        },
        {
          title: '数据长度',
          align: 'center',
          dataIndex: 'columnLength'
        },
        {
          title: '小数精度',
          align: 'center',
          dataIndex: 'scale'
        },
        {
          title: '数据源',
          align: 'center',
          dataIndex: 'dataSource_dictText'
        },
        {
          title: '表名',
          align: 'center',
          dataIndex: 'tableName'
        },
        {
          title: '字段名',
          align: 'center',
          dataIndex: 'tableColumn'
        },
        {
          title: '描述',
          align: 'center',
          dataIndex: 'remark'
        }
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        add: '/index/config/saveIndexCatalog',
        list: '/index/config/listIndex',
        delete: '/index/scSituationIndexInfo/delete',
        deleteBatch: '/index/scSituationIndexInfo/deleteBatch',
        exportXlsUrl: '/index/scSituationIndexInfo/exportXls',
        importExcelUrl: 'index/scSituationIndexInfo/importExcel'

      },
      dictOptions: {},
      superFieldList: [],
      isorter: {
        column: null,
        order: null
      }
    }
  },
  created() {
  },
  methods: {
    searchResetBefore() {
      // this.$refs.superQueryModal.handleReset()
      this.searchReset()
    },
    clearDataSource() {
      this.dataSource = []
      this.ipagination.total = 0
    },
    getSuperFieldList() {
      const fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '指标名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dimensionInfoVoList', text: '维度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '描述', dictCode: '' })
      fieldList.push({ type: 'string', value: 'configId', text: '配置名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dataSource', text: '数据源', dictCode: 'sys_data_source,name,code' })
      fieldList.push({ type: 'string', value: 'tableName', text: '表名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tableColumn', text: '字段名', dictCode: '' })
      fieldList.push({ type: 'int', value: 'dataType', text: '数据类型', dictCode: 'column_data_type' })
      fieldList.push({ type: 'int', value: 'columnLength', text: '数据长度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'scale', text: '小数精度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'unit', text: '统计单位', dictCode: '' })
      fieldList.push({ type: 'int', value: 'isPercent', text: '是否率值', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'groupType', text: '汇聚类型', dictCode: 'index_group_type' })
      // fieldList.push({ type: 'int', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateBy', text: '编辑人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateTime', text: '编辑时间', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleCancel() {
      this.loadData()
      this.visible = false
    },
    handleOk() {
      this.dataSource2 = this.selectedRowKeys

      if (this.dataSource2 == null || this.dataSource2.length == 0) {
        this.$message.success('请选择一条记录!')
        return
      }

      this.confirmLoading = true

      var submitFormData = []

      this.dataSource2.forEach(item => {
        submitFormData.push({ catalogId: this.catalogId, indexId: item })
      })

      httpAction(this.url.add, submitFormData, 'POST').then((res) => {
        if (res.success) {
          this.$message.success('保存成功!')
          this.$emit('loadData', this.dataSource2)
          this.visible = false
        } else {
          this.$message.error(res.message)
        }
        this.confirmLoading = false
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    add(catalogId) {
      this.catalogId = catalogId
      this.visible = true
      this.filters.notCatalogId = catalogId
      this.selectedRowKeys = []
      this.clearDataSource()
      this.loadData()
    }
  }
}
</script>
<style lang="less" scoped>
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
</style>
